package com.ruoyi.web.task;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.domain.SpokenUserCourseTime;
import com.ruoyi.system.service.ISpokenUserCourseTimeService;
import com.sun.jna.platform.win32.Sspi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.sql.Time;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

@Component("CancelLesson")
public class CancelLesson {

    @Autowired
    ISpokenUserCourseTimeService userCourseTimeService;

    public void executeCancel(){
        List<SpokenUserCourseTime> spokenUserCourseTimes = userCourseTimeService.selectWaitCancelLesson();
        for (SpokenUserCourseTime spokenUserCourseTime : spokenUserCourseTimes) {
            // 拼接结束时间
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
            String strDate = spokenUserCourseTime.getChooseDate() + " " + spokenUserCourseTime.getCourseTime().getEndTime();
            LocalDateTime endTime = LocalDateTime.parse(strDate, formatter);
            Long now = System.currentTimeMillis();
            Long endTimeMill = Timestamp.valueOf(endTime).getTime();
            // 大于24小时自动消课
            if(now - endTimeMill > 24 * 60 * 60 * 1000){
                System.out.println("uctid" + spokenUserCourseTime.getUctId() + "----自动消课");
                userCourseTimeService.cancelLessonNum(spokenUserCourseTime.getUctId());
            }
        }
    }
}
